package com.simple.editor.callback;

import com.simple.editor.util.UIUtilities;

import javax.swing.*;

/**
 * Created with IntelliJ IDEA.
 * User: vlad
 * Date: 7/2/13
 * Time: 9:02 AM
 * To change this template use File | Settings | File Templates.
 */
public class UIEnableDisableCallback implements Callback {
    private final JComponent component;

    public UIEnableDisableCallback(JComponent component) {
        this.component = component;
    }

    @Override
    public void onComplete() {
        UIUtilities.invoke(new Runnable() {
            @Override
            public void run() {
                component.setEnabled(true);
            }
        });

    }

    @Override
    public void onFailure(Exception ex) {
        UIUtilities.invoke(new Runnable() {
            @Override
            public void run() {
                component.setEnabled(true);
            }
        });
    }

    @Override
    public void onStart() {
        UIUtilities.invoke(new Runnable() {
            @Override
            public void run() {
                component.setEnabled(false);
            }
        });
    }
}
